package com.bjsxt.controller;


import com.bjsxt.mapper.SurveyDao;
import com.bjsxt.pojo.Question;
import com.bjsxt.pojo.Survey;
import com.bjsxt.service.QuestionServer;
import com.bjsxt.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ReleaseController {

    @Autowired
    private SurveyDao surveyDao;
    @Autowired
    private QuestionServer questionServer;

    @GetMapping("release/{uuid}")
    public String release(@PathVariable("uuid") String uuid, HttpServletRequest request){

        List<Survey> list = surveyDao.query(MapParameter.getInstance().put("state", "进行中").getMap());

        for (Survey survey : list) {
            String url = survey.getUrl();
            if (url.contains(uuid)){
                //查找问卷下的全部问题和选项，放入问卷
                Question question = new Question();
                question.setSurveyId(survey.getId());
                //query主要用到surveyId来查找
                List<Question> questions = questionServer.query(question);
                survey.setQuestions(questions);

                request.getSession().setAttribute("survey",survey);
                System.out.println(survey);
            }
        }
        return "survey/page";
    }


}
